package com.example.mobile2021606185zhn0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private TextView tvMainQ1;
    private RadioGroup ragDemo1;
    private RadioButton radbtn1A;
    private RadioButton radbtn1B;
    private RadioButton radbtn1C;
    private RadioButton radbtn1D;
    private TextView tvMainQ2;
    private RadioGroup ragDemo2;
    private RadioButton radbtn2A;
    private RadioButton radbtn2B;
    private RadioButton radbtn2C;
    private RadioButton radbtn2D;
    private TextView tvMainQ3;
    private RadioGroup ragDemo3;
    private RadioButton radbtn3A;
    private RadioButton radbtn3B;
    private RadioButton radbtn3C;
    private RadioButton radbtn3D;
    private TextView tvMainQ4;
    private RadioGroup ragDemo4;
    private RadioButton radbtn4A;
    private RadioButton radbtn4B;
    private RadioButton radbtn4C;
    private RadioButton radbtn4D;
    private Button btnReset;
    private Button btnSubmit;
    private TextView tvEnd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        ragDemo1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        ragDemo2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        ragDemo3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        ragDemo4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int optionID1 = ragDemo1.getCheckedRadioButtonId();
                int optionID2 = ragDemo2.getCheckedRadioButtonId();
                int optionID3 = ragDemo3.getCheckedRadioButtonId();
                int optionID4 = ragDemo4.getCheckedRadioButtonId();
                if (optionID1 == R.id.radbtn1A & optionID2==R.id.radbtn2B & optionID3==R.id.radbtn3B & optionID4==R.id.radbtn4C) {
                    tvEnd.setText("分数：100分");
                } else if (optionID1 == R.id.radbtn1A & optionID2==R.id.radbtn2C & optionID3==R.id.radbtn3B || optionID2==R.id.radbtn2C & optionID3==R.id.radbtn3B & optionID4==R.id.radbtn4A || optionID1 == R.id.radbtn1A& optionID3==R.id.radbtn3B & optionID4==R.id.radbtn4A) {
                    tvEnd.setText("分数：75分");
                }else if (optionID1 == R.id.radbtn1A & optionID2==R.id.radbtn2C || optionID1 == R.id.radbtn3B& optionID3==R.id.radbtn3B||optionID1 == R.id.radbtn1A& optionID4==R.id.radbtn4A|| optionID2==R.id.radbtn2C & optionID3==R.id.radbtn3B|| optionID2==R.id.radbtn2C & optionID4==R.id.radbtn4A|| optionID3==R.id.radbtn3B & optionID4==R.id.radbtn4A){
                    tvEnd.setText("分数：50分");
                }else if (optionID1 == R.id.radbtn1A  || optionID2==R.id.radbtn2C  || optionID3==R.id.radbtn3B || optionID4==R.id.radbtn4A){
                    tvEnd.setText("分数：25分");
                }else if (optionID1==-1||optionID2==-1||optionID3==-1||optionID4==-1 ){
                    Toast.makeText(MainActivity.this, "请作出选择", Toast.LENGTH_SHORT).show();
                }else{
                    tvEnd.setText("分数：0分");
                }
            }

        });
        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radbtn1A.setChecked(false);
                radbtn1B.setChecked(false);
                radbtn1C.setChecked(false);
                radbtn1D.setChecked(false);
                radbtn2A.setChecked(false);
                radbtn2B.setChecked(false);
                radbtn2C.setChecked(false);
                radbtn2D.setChecked(false);
                radbtn3A.setChecked(false);
                radbtn3B.setChecked(false);
                radbtn3C.setChecked(false);
                radbtn3D.setChecked(false);
                radbtn4A.setChecked(false);
                radbtn4B.setChecked(false);
                radbtn4C.setChecked(false);
                radbtn4D.setChecked(false);
                tvEnd.setText("");
                Toast.makeText(MainActivity.this,"重置完成",Toast.LENGTH_SHORT).show();

            }
        });


    }
    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        tvMainQ1 = (TextView) findViewById(R.id.tv_main_q1);
        ragDemo1 = (RadioGroup) findViewById(R.id.rag_demo1);
        radbtn1A = (RadioButton) findViewById(R.id.radbtn1A);
        radbtn1B = (RadioButton) findViewById(R.id.radbtn1B);
        radbtn1C = (RadioButton) findViewById(R.id.radbtn1C);
        radbtn1D = (RadioButton) findViewById(R.id.radbtn1D);
        tvMainQ2 = (TextView) findViewById(R.id.tv_main_q2);
        ragDemo2 = (RadioGroup) findViewById(R.id.rag_demo2);
        radbtn2A = (RadioButton) findViewById(R.id.radbtn2A);
        radbtn2B = (RadioButton) findViewById(R.id.radbtn2B);
        radbtn2C = (RadioButton) findViewById(R.id.radbtn2C);
        radbtn2D = (RadioButton) findViewById(R.id.radbtn2D);
        tvMainQ3 = (TextView) findViewById(R.id.tv_main_q3);
        ragDemo3 = (RadioGroup) findViewById(R.id.rag_demo3);
        radbtn3A = (RadioButton) findViewById(R.id.radbtn3A);
        radbtn3B = (RadioButton) findViewById(R.id.radbtn3B);
        radbtn3C = (RadioButton) findViewById(R.id.radbtn3C);
        radbtn3D = (RadioButton) findViewById(R.id.radbtn3D);
        tvMainQ4 = (TextView) findViewById(R.id.tv_main_q4);
        ragDemo4 = (RadioGroup) findViewById(R.id.rag_demo4);
        radbtn4A = (RadioButton) findViewById(R.id.radbtn4A);
        radbtn4B = (RadioButton) findViewById(R.id.radbtn4B);
        radbtn4C = (RadioButton) findViewById(R.id.radbtn4C);
        radbtn4D = (RadioButton) findViewById(R.id.radbtn4D);
        btnReset = (Button) findViewById(R.id.btn_Reset);
        btnSubmit = (Button) findViewById(R.id.btn_submit);
        tvEnd = (TextView) findViewById(R.id.tv_end);
    }
}